<template>
    <div class="charge-record">
        <el-card shadow="never" class="!border-none">
            <el-alert
                title="温馨提示： 会员账户余额变动记录"
                type="success"
                :closable="false"
                show-icon
            />

            <!-- Header Form Start -->
            <el-form :model="formData" label-width="90px" inline class="mt-[16px]">
                <el-form-item label="充值单号">
                    <el-input
                        class="w-[280px]"
                        v-model="formData.sn"
                        placeholder="请输入充值单号"
                    />
                </el-form-item>
                <el-form-item label="用户信息">
                    <el-input
                        class="w-[280px]"
                        v-model="formData.keyword"
                        placeholder="请输入用户信息"
                    />
                </el-form-item>
                <el-form-item label="支付方式">
                    <el-select v-model="formData.payWay" class="w-[280px]" placeholder="请选择">
                        <el-option label="全部" value></el-option>
                        <el-option label="余额支付" :value="1"></el-option>
                        <el-option label="微信支付" :value="2"></el-option>
                        <el-option label="支付宝支付" :value="3"></el-option>
                    </el-select>
                </el-form-item>
                <el-form-item label="支付状态">
                    <el-select v-model="formData.payStatus" class="w-[280px]" placeholder="请选择">
                        <el-option label="全部" value></el-option>
                        <el-option label="未支付" :value="0"></el-option>
                        <el-option label="已支付" :value="1"></el-option>
                    </el-select>
                </el-form-item>
                <el-form-item label="下单时间">
                    <data-picker
                        v-model:start_time="formData.startTime"
                        v-model:end_time="formData.endTime"
                    >
                    </data-picker>
                </el-form-item>
                <el-form-item>
                    <div class="ml-[20px]">
                        <el-button type="primary" @click="resetPage">查询</el-button>
                        <el-button @click="resetParams">重置</el-button>
                    </div>
                </el-form-item>
            </el-form>
            <!-- Header Form End -->
        </el-card>

        <el-card shadow="never" class="!border-none mt-4">
            <!-- Main TableData Start -->
            <div class="m-t-20">
                <el-table
                    ref="tableData"
                    :data="pager.lists"
                    style="width: 100%"
                    v-loading="pager.loading"
                >
                    <el-table-column property="sn" label="订单编号" min-width="140" />
                    <el-table-column property="nickname" label="用户昵称" min-width="140">
                        <template #default="{ row }">
                            <div class="flex items-center">
                                <el-image class="w-[40px] h-[40px]" :src="row.avatar"></el-image>
                                <div class="ml-2">{{ row.nickname }}</div>
                            </div>
                        </template>
                    </el-table-column>
                    <el-table-column property="orderAmount" label="充值金额" max-width="140" />
                    <el-table-column label="支付方式" max-width="140">
                        <template #default="{ row }">
                            <div v-if="row.payWay == 1">余额支付</div>
                            <div v-if="row.payWay == 2">微信支付</div>
                            <div v-if="row.payWay == 3">支付宝支付</div>
                        </template>
                    </el-table-column>
                    <el-table-column property="payStatus" label="支付状态" max-width="140">
                        <template #default="{ row }">
                            <div v-if="row.payStatus == 0">未支付</div>
                            <div v-if="row.payStatus == 1">已支付</div>
                        </template>
                    </el-table-column>
                    <el-table-column property="createTime" label="下单时间" min-width="140" />
                    <el-table-column property="payTime" label="支付时间" min-width="140" />
                </el-table>
            </div>
            <!-- Main TableData End -->

            <!-- Footer Pagination Start -->
            <div class="flex justify-end mr-2">
                <pagination
                    v-model="pager"
                    @change="getLists"
                    layout="total, prev, pager, next, jumper"
                />
            </div>
            <!-- Footer Pagination End -->
            <layout-footer></layout-footer>
        </el-card>
    </div>
</template>

<script lang="ts" setup>
import { apiRechargeRecord } from '@/api/finance/finance'
import { ref } from 'vue'
import Pagination from '@/components/pagination/index.vue'
import { usePaging } from '@/hooks/usePaging'
import DataPicker from '@/components/data-picker/index.vue'
import LayoutFooter from '@/layout/components/footer.vue'

/** Interface Start **/
interface FormDataObj {
    sn: number | any // 充值订单编号
    keyword?: string // 用户信息
    payWay: number | string // 支付方式
    payStatus?: number | string // 支付状态：0-待支付 1-已支付
    startTime: string // 开始下单时间
    endTime: string // 结束下单时间
}
/** Interface End **/

/** Data Start **/
// 表单数据
const formData = ref<FormDataObj>({
    sn: '',
    keyword: '',
    payWay: '',
    payStatus: '',
    startTime: '',
    endTime: ''
})
const { pager, getLists, resetParams, resetPage } = usePaging({
    fetchFun: apiRechargeRecord,
    params: formData.value
})
/** Data End **/

/** LifeCycle Start **/
getLists()
/** LifeCycle End **/
</script>

<style lang="scss">
.ls-input {
    width: 170px;
}
.el-alert--success.is-light {
    background-color: #edefff;
    color: #4a5dff;
}
</style>
